package com.six.action.settings;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.six.biz.ICustomerManagementBiz;
import com.six.biz.impl.settings.ICustomerManagementBizImpl;
import com.six.vo.Customer;

@Namespace("/settings")  
@ParentPackage(value = "settings") 
public class CustomerManagementAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2742416849995744392L;
	private ICustomerManagementBiz customerManagementBiz = new ICustomerManagementBizImpl();//客户管理业务处理接口
	private int cid;
	private String cname;
	private int cicid;
	private List<Customer> customerlist = new ArrayList<Customer>();
	private String optMark;
	private Customer customer;
	public int getCid() {
		return cid;
	}
	public void setCid(int cid) {
		this.cid = cid;
	}
	public String getCname() {
		return cname;
	}
	public void setCname(String cname) {
		this.cname = cname;
	}
	public int getCicid() {
		return cicid;
	}
	public void setCicid(int cicid) {
		this.cicid = cicid;
	}
	public List<Customer> getCustomerlist() {
		return customerlist;
	}
	public void setCustomerlist(List<Customer> customerlist) {
		this.customerlist = customerlist;
	}
	public String getOptMark() {
		return optMark;
	}
	public void setOptMark(String optMark) {
		this.optMark = optMark;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	/**
	 * 恢复客户活动状态
	 */
	@Action(value = "revertCustomerAction")
	public String revertCustomer() throws Exception {
		customerManagementBiz.revertCustomer(cid);
		return null;
		
	}
	/**
	 * 删除客户（将客户状态置为删除状态）
	 */
	@Action(value = "deleteCustomerAction")
	public String deleteCustomer() throws Exception {
		customerManagementBiz.deleteCustomer(cid);
		return null;
		
	}
	/**
	 * 提交客户信息新增和更新处理响应
	 */
	@Action(value = "optCusotmerManagementAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/settings/custom_manage.html")
			}
	)
	public String optCusotmerManagement() throws Exception {
		//保存
		customerManagementBiz.saveCustomer(customer);
		//更新
//		customerManagementBiz.updateCustomer(customer);
		return SUCCESS;
		
		
	}
	/**
	 * 异步响应查询指定客户信息，封装成 JSON 表达式返回
	 */
	@Action(value = "queryCustomerInfoAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/UserManagement.jsp")
				,@Result(name = "input", location = "/manager/UserManagement.jsp") 			}
	)
	public String queryCustomerInfo() throws Exception {
		customerManagementBiz.findCustomerById(cid);
		return null;
		
	}
	/**
	 * 响应查询客户信息列表
	 */
	@Action(value = "customerListQueryAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/settings/custom_query.jsp")
			}
	)
	public String queryCustomers() throws Exception {
		customerManagementBiz.findCustomers(cid, cname, cicid);
		return null;
		
	}


}
